package redis

import (
	"fmt"
	"github.com/go-redis/redis/v8"
	"go.uber.org/zap"
	"web_app/setting"
)

var RED *redis.Client

func Init(redisConfig *setting.RedisConfig) error {
	RED = redis.NewClient(&redis.Options{
		Addr:         fmt.Sprintf("%s:%d", redisConfig.Host, redisConfig.Port),
		DB:           redisConfig.DB,
		Password:     redisConfig.Password,
		PoolSize:     redisConfig.PoolSize,
		MinIdleConns: redisConfig.MinIdleConn,
	})

	var _, err = RED.Ping(RED.Context()).Result()
	if err != nil {
		zap.L().Error("连接redis出错", zap.Error(err))

	}

	return err
}
